import Vue from 'vue';
import App from './app.vue';
import iView from 'iview';
import {router} from './router/index';
//import CKEditor from '@ckeditor/ckeditor5-vue'
import 'famfamfam-flags/dist/sprite/famfamfam-flags.css';
import './theme.less';
import Ajax from './lib/ajax';
import Util from './lib/util';
import SignalRAspNetCoreHelper from './lib/SignalRAspNetCoreHelper';
Vue.use(iView);
//Vue.use( CKEditor );
import store from './store/index';
Vue.config.productionTip = false;
import { appRouters,otherRouters} from './router/router';
if(!abp.utils.getCookieValue('Abp.Localization.CultureName')){
  let language=navigator.language;
  abp.utils.setCookieValue('Abp.Localization.CultureName',language,new Date(new Date().getTime() + 5 * 365 * 86400000),abp.appPath);
}

import Page from '@common/models/Page';
Page.handleData = function(action, data, callback, errorCallback) {
  Ajax.post(action, data).then(response => {
    callback(response.data.result);
  }).catch(error => {
    errorCallback(error);
  });
}


Ajax.get('/AbpUserConfiguration/GetAll').then(data=>{
	Util.abp=Util.extend(true,Util.abp,data.data.result);

	new Vue({
		render: h => h(App),
		router:router,
		store:store,
		data: {
			currentPageName: ''
		},
		async mounted () {
			this.currentPageName = this.$route.name as string;
			
			// 得到所有后台设置
			await this.$store.dispatch({
				type:'setting/getAllSettings'
			});
		
			await this.$store.dispatch({
				type:'session/init'
			})
			if(!!this.$store.state.session.user&&this.$store.state.session.application.features['SignalR']){
				if (this.$store.state.session.application.features['SignalR.AspNetCore']) {
					SignalRAspNetCoreHelper.initSignalR();
				}
			}
			this.$store.commit('app/initCachepage');
			this.$store.commit('app/updateMenulist');
		},
		created () {
			let tagsList:Array<any> = [];
			appRouters.map((item) => {
				if (item.children.length <= 1) {
					tagsList.push(item.children[0]);
				} else {
					tagsList.push(...item.children);
				}
			});
			this.$store.commit('app/setTagsList', tagsList);
		}
	}).$mount('#app')
})

